<?php

/**
 * This file is part of the Framework03 PHP framework.
 * @package Framework03
 * @author Walter Tamboer
 */

// Let's get the root directory, this will be useful when setting all the paths.
$root = dirname(dirname(__FILE__));

// The include paths so that all application items can be found.
set_include_path(get_include_path() . PATH_SEPARATOR . $root . '/../library');

// Make sure that PHP actually shows the errors.
ini_set('display_errors', true);

// Also make sure that PHP shows startup errors.
ini_set('display_startup_errors', true);

// We want to show all errors including strict errors because we don't make mistakes.
error_reporting(E_ALL | E_STRICT);

// We want automatic loading of classes because we're lazy.
require_once 'FW/Loader.php';
FW_Loader::startAutoLoading();

// Let's create a connection with the database.
$db = FW_Database::factory('MySQL', array(
    'host' => 'localhost',
    'username' => 'root',
    'password' => 'root',
    'dbname' => 'test'
));
FW_Database_Table::setAdapter($db);

class MyDatabaseTable extends FW_Database_Table
{
    public function getTableName()
    {
        return 'mytable';
    }
}

$table = new MyDatabaseTable();

// First insert some data into the table...
for ($i = 0; $i < 5; ++$i)
{
    $statement = $table->insert(array(
        'name' => 'Name ' . $i,
        'value' => time()
    ));
}

// Now select all the data from the database table and list it here.
$rowset = $table->select(array('name', 'value'));

echo '<pre>';
foreach ($rowset as $row)
{
    print_r($row);
}
echo '</pre>';

// Last truncate the table and you'll see that the table is empty when you refresh.
$statement = $table->truncate();
